<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.dati.bean.*,com.dati.dao.*,com.UserModule.bean.*"%>  
<%@ page import="util.*" %>
<%

	  //---------分页
	  	List<Answer> datiList=(ArrayList<Answer>) session.getAttribute("datiList");
	    int currentPage=1;
	    if(request.getParameter("Page")!=null)
	    {
	    	datiList=(ArrayList) session.getAttribute("datiList");
	    	currentPage=Integer.parseInt(request.getParameter("Page"));
	    }
	    List<DatiType> datiTypeList = (ArrayList<DatiType>)session.getAttribute("datiTypeList");
	    String datiSelected = session.getAttribute("datiSelected").toString();
	    String content = session.getAttribute("content").toString();
%>
<jsp:include page="../head.jsp"></jsp:include>
<body>
<div id="pager">
<jsp:include page="../top.jsp"><jsp:param name="topCurrent" value="6" /></jsp:include>    
<jsp:include page="Left.jsp">
<jsp:param name="um" value="13" /></jsp:include> 
		<section id="container">
        <div id="crumbs">
        	答题资源库 &raquo; 答题列表
        </div>
    <div id="main">
			<div class="tabs">
				<ul class="tabs-nav clearfix">
					<li>
						答题列表
					</li>
					<li>
						导入答题信息
					</li>
					<li>
						新增答题信息
					</li>
				</ul>
				<div class="tabs-panel">
			<%
			try{
		 	 String resultSM=session.getAttribute("result").toString();
			 if(!resultSM.equals("")){
				 out.println("<script>alertmess('"+resultSM+"');</script>");
				 session.removeAttribute("result");
			 }
			 }catch(Exception ex){
			 
			 }
		 	%>
				 <form action="" method="post" id="form1" name="form2">
					<table width="100%" class="datalist">
						<thead>
						<tr>
								<th colspan="8" class="tl">
								                                       答题类型
												<select id="datitype" name="datitype">
													<option value="0">
													请选择
													</option>
													 <%
													 if(datiTypeList!=null&&datiTypeList.size()>0){
														for(DatiType datiType:datiTypeList){
														%>
														<option value="<%=datiType.getAnswerTypeId() %>"
														<%
														if(datiSelected.equals(datiType.getAnswerTypeId())){
															%>
															selected="selected"
														<%}
														%>
														>
														  <%=datiType.getTypeName() %>
														</option>
														<%
													}	 }
													 %>
												
												</select>
												内容
												<input type="text" id="content" name="content"   value="<%=content %>" />
												<input type="button" value="查询" onclick="searcherByDati('../DatiServlet?method=looksearch')" />&nbsp;&nbsp;
												<input type="button" value="批删" onclick="deleteSmsAllSM('deleteAll','../DatiServlet?method=deleteAll&content=<%=content %>&datiSelected=<%=datiSelected %>')" />&nbsp;&nbsp;
											   <!-- <input type="button" value="导出" onclick="window.location='../upload/export3.xls'" /> --> 
											     
								</th>
							</tr>
							<tr>
								<td class="tc">
									<input type="checkbox" title="全选" onClick="check_allSM('deleteAll')"/>
								</td>
								<td width="5%">
									序号
								</td>
								<td width="10%">
									答题类型
								</td>
							    <td width="35%">
									答题内容
								</td>
								 <td width="12%">
									正确答案
								</td>
								<td width="10%">
									上传号码
								</td>
								<td width="20%">
									创建时间
								</td>
								<td width="8%">
									操作
								</td>
							</tr>
							
						</thead>
						<%
						if(datiList!=null){
							/**String[][] exportArray=new String[dianboList.size()+1][4];
							exportArray[0][0]="答题类型";
				        	exportArray[0][1]="答题内容";
				        	exportArray[0][2]="上传号码";
				        	exportArray[0][3]="创建时间";
				        	for(int rowIndex=1;rowIndex<dianboList.size()+1;rowIndex++)
				        	{
				        		    Dianbo db=dianboList.get(rowIndex-1);
				        			exportArray[rowIndex][0]=""+new DianboTypeDao().getDianboType(db.getTypeId());
				        			exportArray[rowIndex][1]=""+db.getQsContent();
				        			if(db.getQsUpPhone()==null){
				        				exportArray[rowIndex][2]="";
				        			}else{
				        				exportArray[rowIndex][2]=""+db.getQsUpPhone();
				        			}
				        			exportArray[rowIndex][3]=""+db.getQsUpTime().substring(0,19);
				        	}
				        	FileOperate.setExcelSavePath(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
				        	FileOperate.deleteFile(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
				        	FileOperate.writeExcel(exportArray);*/
							int i=0;  
							//--------------分页
							MyPagination mPage=new MyPagination();
							datiList=mPage.getInitPage(datiList,currentPage,10);
							if (datiList != null && datiList.size() > 0) {
											
							for (Answer answer : datiList) {
								String datiTypeName = "";
								String middleId = answer.getAnswerMiddleId();//中间表中的ID
								String contentT = "";
								String seriseId="";//系列ID
								String upPhone="";
								String rightAnswer="";
								String conditionMidd="answerMiddleId ='"+middleId+"'";
								List<DatiMiddle> datiMiddleList = new DatiDao().getDatiMiddle("tb_answer_middle","",conditionMidd);
								if(datiMiddleList!=null&&datiMiddleList.size()>0){
									contentT=datiMiddleList.get(0).getAnswerContent();
									rightAnswer=datiMiddleList.get(0).getRightAnswer();
									seriseId = datiMiddleList.get(0).getSeriseId();
									Xulie xulie = new DatiTypeDao().getXulie(seriseId);
									String datiType = xulie.getAnswerTypeId();//得到类型的ID
									String conditionDati = "answerTypeId='"+datiType+"'";
									List<DatiType> datiTypeListT = new DatiTypeDao().getAllDaTiType("tb_answer_type","",conditionDati);
									if(datiTypeListT!=null&&datiTypeListT.size()>0){
										datiTypeName = datiTypeListT.get(0).getTypeName();
									}
								}
								if(answer.getAnswerUpPhone().equals("")){
									upPhone="人工导入";
								}else{
									upPhone=answer.getAnswerUpPhone();
								}
							i++;
						%>
						<tr>
							<td class="tc">
								<input name="deleteAll" id = "deleteAll" type="checkbox" value="<%=answer.getAnswerId()%>"/>
							</td>
				  			 <td><%=((10*(currentPage-1))+i) %></td>
							<td><%=datiTypeName%></td>
						    <script type="text/javascript">
								$(function(){
					 				$('#demo-basic<%=i%>').poshytip();
								
					   			})
				  			 </script>
							<td><a id="demo-basic<%=i%>" title="<%=contentT%>"><%=new UtilDAO().sub_String(contentT)%></a></td>
							<td><%=rightAnswer %></td>
		        			<td><%=upPhone%></td>
							<td><%=answer.getAnswerUpTime().substring(0,19)%></td>
							<td class="tc">
							    
								<a title="删除该记录" class="duanyu_del" style="cursor:hand" onClick="deleteOneDati('../DatiServlet?method=deleteOneDati&datiId=<%=answer.getAnswerId() %>&content=<%=content %>&datiSelected=<%=datiSelected %>')">删除</a>
							</td>
						</tr> 
					   <%
					   }
					   }
					   
					   %>
					   <%=mPage.printCtrl("hudong/datiList.jsp",currentPage,"&content="+content) %>
						<%}
						else{
								/**			    String[][] exportArray=new String[1][4];
										      	exportArray[0][0]="手机号码";
									        	exportArray[0][1]="创建人";
									        	exportArray[0][2]="创建时间";
									 			FileOperate.setExcelSavePath(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
									        	FileOperate.deleteFile(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
									        	FileOperate.writeExcel(exportArray);*/
					        	
							}
						%>
					</table>
				</form>
				</div>
				<div class="tabs-panel">
				    <form id="formimport" name="formimport" enctype="multipart/form-data"  method="post" action="">
                	<table width="100%" class="datalist">
                	<tr>
                	<td class="tc">导入模版：</td>
                	<td>
                	    <a href="./module/dati.xls" >点击这里下载导入模板</a>
                	</td>
                	</tr>
                      <tr>
                        <td  class="tc">导入答题信息：</td>
                        <td>
                           <input  type="file" id="daoru" name="daoru" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="insertImport()" value=" 提  交 " /></td>
                        	<script type="text/javascript">
                        	//验证上传格式
                        	function insertImport(){
                        			var fileName = document.getElementById("daoru").value;
                        			var lastFileName = encodeURI(fileName);
                        			lastFileName = encodeURI(lastFileName);
                        			 var file_Name = fileName.split(".")[fileName.split(".").length-1];
                        			if(file_Name=="xls"||file_Name=="XLS")
                        			{
                        			 
                        			 }else
                        			 {
                        			 	alert("上传文件格式不对，请重新导入！");
                        			 	return ;
                        			 }
                        			formimport.action="./DatiServlet?method=importDati&realImagePath="+lastFileName;
                        			formimport.submit();
                        		}
                        	</script>
                      </tr>
                        </table>
                        </form>
				</div>
				<div class="tabs-panel">
				    <form id="formadd" name="formadd"    method="post" action="">
                	<table width="100%" class="datalist">
                	<tr>
                		<td class="tc">选择答题类型</td>
                		<td>
												<select id="datitypeadd" name="datitypeadd" onclick="selectDati(datitypeadd.value)">
													<option value="0">
													请选择
													</option>
													 <%
													 if(datiTypeList!=null&&datiTypeList.size()>0){
													for(DatiType dtType:datiTypeList){
													%>
													<option value="<%=dtType.getAnswerTypeId() %>">
													  <%=dtType.getTypeName() %>
													</option>
														<%
													}	
													 }
													 %>
												
												</select>
												 <input type="hidden" name="dati_Type" id="dati_Type" value="0">
												</td>
                	</tr>
                	 <tr style="display:none" id="xilie"><th scope="row">系列</th><td><div id="xilieList"></div>
                	 <input type="hidden" name="datiValue" id="datiValue" value=""/>
                	 </td></tr>
                      <tr>
                        <td  class="tc">新增答题信息：</td>
                        <td>
                           <input  type="text" id="daticontent" size="50"   name="daticontent" value="" />
                        </td>
                        </tr>
                      <tr>
                        <td  class="tc">正确答案：</td>
                        <td>
                           <input  type="text" id="datianswer" size="20"  name="datianswer" value="" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="addDati()" value=" 提  交 " /></td>
                        	
                      </tr>
                        </table>
                        </form>
				</div>
		</div>
	</div>

		
		</section>
		</div>
		  <jsp:include page="../foot.jsp"></jsp:include>
	</body>
</html>
